﻿using KC.Business.Articleulator;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Data;
using System.Collections.Generic;

namespace KC.Business.ArticleulatorTests
{
	[TestClass()]
	public class ArticleulatorTest
	{
		private TestContext testContextInstance;
		public TestContext TestContext {
			get { return testContextInstance; }
			set { testContextInstance = value; } }
		private readonly string cs = System.Configuration.ConfigurationManager.ConnectionStrings["SQL"].ConnectionString;

		#region ConvertDownloadPageRowToPlaintext
		[TestMethod(), TestCategory("Integration")]
		public void ConvertDownloadPageRowToPlaintextTest1()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("ID", typeof(int));
			dt.Columns.Add("DocText", typeof(string));
			dt.Columns.Add("URL", typeof(string));
			dt.Columns.Add("FormattedText");

			DataRow dr = dt.NewRow();
			dr["ID"] = -1;
			dr["URL"] = "http://www.example.com";
			dr["DocText"] = "<html><body>This is a test.  This only a test.  Had this been an actual emergency, you would be screwed without an adult to tell you what to do.</body></html>";

			string expected = "this is a test.this only a test.had this been an actual emergency, you would be screwed without an adult to tell you what to do."; 
			string actual = Articleulator.Articleulator.ConvertDownloadPageRowToPlaintext(dr);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void ConvertDownloadPageRowToPlaintextTest2()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("ID", typeof(int));
			dt.Columns.Add("DocText", typeof(string));
			dt.Columns.Add("URL", typeof(string));
			dt.Columns.Add("FormattedText");

			DataRow dr = dt.NewRow();
			dr["ID"] = -1;
			dr["URL"] = "http://www.example.com";
			dr["DocText"] = "<html><body><!--This is a test.  This only a test.  Had this been an actual emergency, you would be screwed without an adult to tell you what to do.--></body></html>";

			string expected = "";
			string actual = Articleulator.Articleulator.ConvertDownloadPageRowToPlaintext(dr);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void ConvertDownloadPageRowToPlaintextTest3()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("ID", typeof(int));
			dt.Columns.Add("DocText", typeof(string));
			dt.Columns.Add("URL", typeof(string));
			dt.Columns.Add("FormattedText");

			DataRow dr = dt.NewRow();
			dr["ID"] = -1;
			dr["URL"] = "http://www.example.com";
			dr["DocText"] = "<html><body>This is a test.  <!--This only a test.   -->  Had this been an actual emergency, you would be screwed without an adult to tell you what to do.</body></html>";

			string expected = "this is a test.had this been an actual emergency, you would be screwed without an adult to tell you what to do.";
			string actual = Articleulator.Articleulator.ConvertDownloadPageRowToPlaintext(dr);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void ConvertDownloadPageRowToPlaintextTest4()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("ID", typeof(int));
			dt.Columns.Add("DocText", typeof(string));
			dt.Columns.Add("URL", typeof(string));
			dt.Columns.Add("FormattedText");

			DataRow dr = dt.NewRow();
			dr["ID"] = -1;
			dr["URL"] = "http://www.example.com";
			dr["DocText"] = "<html><body>This is a test.  <i>Had</i> this been an actual emergency, you would be screwed without an adult to tell you what to do.</body></html>";

			string expected = "this is a test.had this been an actual emergency, you would be screwed without an adult to tell you what to do.";
			string actual = Articleulator.Articleulator.ConvertDownloadPageRowToPlaintext(dr);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void ConvertDownloadPageRowToPlaintextTest5()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("ID", typeof(int));
			dt.Columns.Add("DocText", typeof(string));
			dt.Columns.Add("URL", typeof(string));
			dt.Columns.Add("FormattedText");

			DataRow dr = dt.NewRow();
			dr["ID"] = -1;
			dr["URL"] = "http://www.example.com";
			dr["DocText"] = "<html><body>This is a test.  <sup>Had</sup> this <sub>been</sub> an <a>actual</a> emergency, <img />you would be screwed without an adult to tell you what to do.</body></html>";

			string expected = "this is a test.this an actual emergency, you would be screwed without an adult to tell you what to do.";
			string actual = Articleulator.Articleulator.ConvertDownloadPageRowToPlaintext(dr);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void ConvertDownloadPageRowToPlaintextTest6()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("ID", typeof(int));
			dt.Columns.Add("DocText", typeof(string));
			dt.Columns.Add("URL", typeof(string));
			dt.Columns.Add("FormattedText");

			DataRow dr = dt.NewRow();
			dr["ID"] = -1;
			dr["URL"] = "http://www.example.com";
			dr["DocText"] = "<html><body>This is a test.  You <style>bleh blah crapola </style>would be screwed without an <script>adult</script> to <script type=\"blah\">tell</script> you what to do.</body></html>";

			string expected = "this is a test.you would be screwed without an to you what to do.";
			string actual = Articleulator.Articleulator.ConvertDownloadPageRowToPlaintext(dr);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void ConvertDownloadPageRowToPlaintextTest7()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("ID", typeof(int));
			dt.Columns.Add("DocText", typeof(string));
			dt.Columns.Add("URL", typeof(string));
			dt.Columns.Add("FormattedText");

			DataRow dr = dt.NewRow();
			dr["ID"] = -1;
			dr["URL"] = "http://www.example.com";
			dr["DocText"] = "tomato<html><body>This is a test.  You <style>bleh blah crapola </style>would be screwed without an <script>adult</script> to <script type=\"blah\">tell</script> you what to do.</body></html>";

			string expected = null;
			string actual = Articleulator.Articleulator.ConvertDownloadPageRowToPlaintext(dr);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void ConvertDownloadPageRowToPlaintextTest8()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("ID", typeof(int));
			dt.Columns.Add("DocText", typeof(string));
			dt.Columns.Add("URL", typeof(string));
			dt.Columns.Add("FormattedText");

			DataRow dr = dt.NewRow();
			dr["ID"] = -1;
			dr["URL"] = "http://www.http://www.cambridge.edu";
			dr["DocText"] = "<html><body>This is a test.  You <style>bleh blah crapola </style>would be <div>screwed</div> without an <script>adult</script> to <script type=\"blah\">tell</script> you what to do.</body></html>";

			string expected = null;
			string actual = Articleulator.Articleulator.ConvertDownloadPageRowToPlaintext(dr);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void ConvertDownloadPageRowToPlaintextTest9()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("ID", typeof(int));
			dt.Columns.Add("DocText", typeof(string));
			dt.Columns.Add("URL", typeof(string));
			dt.Columns.Add("FormattedText");

			DataRow dr = dt.NewRow();
			dr["ID"] = -1;
			dr["URL"] = "http://www.example.com";
			dr["DocText"] = "<html><body>This is a test...  <i>Had</i> this been an actual emergency, you would be screwed without an adult to tell you what to do.. .. . .</body></html>";

			string expected = "this is a test.had this been an actual emergency, you would be screwed without an adult to tell you what to do.";
			string actual = Articleulator.Articleulator.ConvertDownloadPageRowToPlaintext(dr);
			Assert.AreEqual(expected, actual);
		}
		#endregion ConvertDownloadPageRowToPlaintext
		#region DetectWordType
		[TestMethod(), TestCategory("Integration")]
		public void DetectWordTypeTest1()
		{
			string word = "costly";
			Articleulator.Articleulator.WordType? expected = Articleulator.Articleulator.WordType.Adjective;
			Articleulator.Articleulator.WordType? actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void DetectWordTypeTest2()
		{
			string word = "about";
			Articleulator.Articleulator.WordType? expected = Articleulator.Articleulator.WordType.Preposition;
			Articleulator.Articleulator.WordType? actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);
			
			word = "since";
			expected = Articleulator.Articleulator.WordType.Preposition;
			actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);

			word = "despite";
			expected = Articleulator.Articleulator.WordType.Preposition;
			actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void DetectWordTypeTest3()
		{
			string word = "ye";
			Articleulator.Articleulator.WordType? expected = Articleulator.Articleulator.WordType.Article;
			Articleulator.Articleulator.WordType? actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);
			
			word = "a";
			expected = Articleulator.Articleulator.WordType.Article;
			actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);

			word = "the";
			expected = Articleulator.Articleulator.WordType.Article;
			actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void DetectWordTypeTest4()
		{
			string word = "so";
			Articleulator.Articleulator.WordType? expected = Articleulator.Articleulator.WordType.Adverb;
			Articleulator.Articleulator.WordType? actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);

			word = "because";
			expected = Articleulator.Articleulator.WordType.Adverb;
			actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);

			word = "sometimes";
			expected = Articleulator.Articleulator.WordType.Adverb;
			actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void DetectWordTypeTest5()
		{
			string word = "wherever";
			Articleulator.Articleulator.WordType? expected = Articleulator.Articleulator.WordType.Conjunction;
			Articleulator.Articleulator.WordType? actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void DetectWordTypeTest6()
		{
			string word = "cancelloaded";
			Articleulator.Articleulator.WordType? expected = null;
			Articleulator.Articleulator.WordType? actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void DetectWordTypeTest7()
		{
			string word = "transmitting";
			Articleulator.Articleulator.WordType? expected = Articleulator.Articleulator.WordType.Verb;
			Articleulator.Articleulator.WordType? actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);
			Assert.AreEqual(word, "transmit");

			word = "transmitted";
			expected = Articleulator.Articleulator.WordType.Verb;
			actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);
			Assert.AreEqual(word, "transmit");

			word = "specified";
			expected = Articleulator.Articleulator.WordType.Verb;
			actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);
			Assert.AreEqual("specify", word);
		}
		[TestMethod(), TestCategory("Integration")]
		public void DetectWordTypeTest8()
		{
			string word = "swing";
			Articleulator.Articleulator.WordType? expected = Articleulator.Articleulator.WordType.Noun;
			Articleulator.Articleulator.WordType? actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);

			word = "ping";
			expected = Articleulator.Articleulator.WordType.Noun;
			actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);

			word = "Ted";
			expected = Articleulator.Articleulator.WordType.Noun;
			actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);

			word = "Kevin";
			expected = Articleulator.Articleulator.WordType.Noun;
			actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void DetectWordTypeTest9()
		{
			string word = "crazily";
			Articleulator.Articleulator.WordType? expected = Articleulator.Articleulator.WordType.Adverb;
			Articleulator.Articleulator.WordType? actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);

			word = "fsdafsdly";
			expected = Articleulator.Articleulator.WordType.Adverb;
			actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);
		}
		[TestMethod(), TestCategory("Integration")]
		public void DetectWordTypeTest10()
		{
			string word = "fsdafdfaaffsdahkjafsd";
			Articleulator.Articleulator.WordType? expected = null;
			Articleulator.Articleulator.WordType? actual = Articleulator.Articleulator.DetectWordType(ref word);
			Assert.AreEqual(expected, actual);
		}
		#endregion DetectWordType
		#region ExtractSentences

		[TestMethod(), TestCategory("Integration")]
		public void ExtractSentencesTest1()
		{
			string plaintext = "One two three four five five five. Six seven eight nine ten one four eight.";
			List<string> expected = new List<string>() { "One two three four five five five.", "Six seven eight nine ten one four eight." };
			List<string> actual = Articleulator.Articleulator.ExtractSentences(plaintext);
			foreach (string sent in expected)
				Assert.IsTrue(actual.Contains(sent));
			foreach (string sent in actual)
				Assert.IsTrue(expected.Contains(sent));

			for (int i = 0; i < 5; i++) {
				System.Threading.Thread.Sleep(2000);
				try {  // SQL not updating quickly enough for the test to see the rows
					foreach (string sent in expected) {
						Assert.IsTrue(int.Parse(KC.DataAccess.Global.Global.CallSql_Query(cs, "select count(*) from sentences with (nolock) where sentence='" + sent.Replace("'", "''") + "'").Rows[0][0].ToString()) > 1, "failed on sentence: " + sent);
						KC.DataAccess.Global.Global.CallSql_Query(cs, "delete sentences where sentence='" + sent.Replace("'", "''") + "'"); }
					return; }
				catch { } }
		}
		[TestMethod(), TestCategory("Integration"), ExpectedException(typeof(ArgumentNullException))]
		public void ExtractSentencesTest2()
		{
			List<string> actual = Articleulator.Articleulator.ExtractSentences(null);
		}

		#endregion ExtractSentences
		#region GenerateSentence

		[TestMethod(), TestCategory("Integration")]
		public void GenerateSentenceTest1()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("ID", typeof(int));
			dt.Columns.Add("Sentence", typeof(string));
			DataRow dr = dt.NewRow();
			dr["ID"] = -1;
			dr["Sentence"] = "I am the very model of a modern Major-General.";
			
			Articleulator.Articleulator.GenerateSentence(dr);
			System.Threading.Thread.Sleep(1000);
			string actual = KC.DataAccess.Global.Global.CallSql_Query(cs, "select top 1 sentence from sentences with (nolock) order by id desc").Rows[0][0].ToString();

			// I am the very model till a modern major-general.

			int matches = 0;
			foreach (char c in (string)dr["Sentence"])
				if (actual.Contains(c.ToString())) matches++;
			double perc = (double)actual.Length * 0.7D; // probability function as we can't predict which random replacements will occur.
			Assert.IsTrue(matches > perc);
			Assert.IsTrue(matches < actual.Length);
			KC.DataAccess.Global.Global.CallSql_Query(cs, "delete sentences where sentence='" + actual.Replace("'", "''") + "'");
		}
		[TestMethod(), TestCategory("Integration"), ExpectedException(typeof(ArgumentNullException))]
		public void GenerateSentenceTest2()
		{
			Articleulator.Articleulator.GenerateSentence(null);
		}
		[TestMethod(), TestCategory("Integration")]
		public void GenerateSentenceTest3()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("ID", typeof(int));
			dt.Columns.Add("Sentence", typeof(string));
			DataRow dr = dt.NewRow();
			dr["ID"] = -1;
			dr["Sentence"] = "<>!*''#  Wakka wakka bang splat tick tick hash.";

			Articleulator.Articleulator.GenerateSentence(dr);
			System.Threading.Thread.Sleep(1000);
			string actual = KC.DataAccess.Global.Global.CallSql_Query(cs, "select top 1 sentence from sentences with (nolock) order by id desc").Rows[0][0].ToString();
			Assert.IsFalse(actual.Contains("wakka"));
		}
		[TestMethod(), TestCategory("Integration")]
		public void GenerateSentenceTest4()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("ID", typeof(int));
			dt.Columns.Add("Sentence", typeof(string));
			DataRow dr = dt.NewRow();
			dr["ID"] = -1;
			dr["Sentence"] = "Money's hard to come by, but not if you're crafty.";

			Articleulator.Articleulator.GenerateSentence(dr);
			System.Threading.Thread.Sleep(1000);
			string actual = KC.DataAccess.Global.Global.CallSql_Query(cs, "select top 1 sentence from sentences with (nolock) order by id desc").Rows[0][0].ToString();

			// I am the very model till a modern major-general.

			int matches = 0;
			foreach (char c in (string)dr["Sentence"])
				if (actual.Contains(c.ToString())) matches++;
			double perc = (double)actual.Length * 0.7D; // probability function as we can't predict which random replacements will occur.
			Assert.IsTrue(matches > perc);
			Assert.IsTrue(matches < actual.Length);
			KC.DataAccess.Global.Global.CallSql_Query(cs, "delete sentences where sentence='" + actual.Replace("'", "''") + "'");
		}

		#endregion GenerateSentence
		#region ParseBody

		[TestMethod(), TestCategory("Integration")]
		public void ParseBodyTest1()
		{
			DataTable dt = new DataTable();
			dt.Columns.Add("ID", typeof(int));
			dt.Columns.Add("DocText", typeof(string));
			dt.Columns.Add("URL", typeof(string));
			dt.Columns.Add("FormattedText");

			DataRow dr = dt.NewRow();
			dr["ID"] = -1;
			dr["URL"] = "http://www.example.com";
			dr["DocText"] = "<html><body>This is a test.  This only a test.  Had this been an actual emergency, you would be screwed without an adult to tell you what to do.</body></html>";

			Articleulator.Articleulator.ParseBody(dr);

			string expected = "Had this been an actual emergency, you would be screwed without an adult to tell you what to do.";
			Assert.IsTrue(int.Parse(KC.DataAccess.Global.Global.CallSql_Query(cs, "select count(id) from sentences where sentence='" + expected.Replace("'", "''") + "'").Rows[0][0].ToString()) > 0);
			KC.DataAccess.Global.Global.CallSql_Query(cs, "delete sentences where sentence='" + expected.Replace("'", "''") + "'");
		}
		[TestMethod(), TestCategory("Integration"), ExpectedException(typeof(ArgumentNullException))]
		public void ParseBodyTest2()
		{
			Articleulator.Articleulator.ParseBody(null);
		}

		#endregion ParseBody
		#region ReplaceSimilarWord

		[TestMethod(), TestCategory("Integration")]
		public void ReplaceSimilarWordTest1()
		{
			string word = "til";
			string actual = Articleulator.Articleulator.ReplaceSimilarWord(word);
			Assert.AreNotEqual(word, actual); // did not return the same word it was passed
			DataTable types = KC.DataAccess.Global.Global.CallSql_Query(cs, "select wordtype from words where word='" + word + "' or word='" + actual + "'");
			Assert.IsTrue(types.Rows.Count > 1); // replacement words exist
			Assert.AreEqual(types.Rows[0][0].ToString(), types.Rows[1][0].ToString()); // types match
		}
		[TestMethod(), TestCategory("Integration"), ExpectedException(typeof(ArgumentNullException))]
		public void ReplaceSimilarWordTest2()
		{
			Articleulator.Articleulator.ReplaceSimilarWord(null);
		}

		#endregion ReplaceSimilarWord
		#region SpiderLink

		[TestMethod(), TestCategory("Integration")]
		public void SpiderLinkTest1()
		{
			DataTable dt = KC.DataAccess.Global.Global.CallSql_Query(cs, "select top 1 * from links where result='' order by id desc");
			if (dt == null || dt.Rows.Count == 0)
			{
				Assert.Inconclusive("No rows to test on.");
				return;
			}
			DataRow dr = dt.Rows[0];
			Articleulator.Articleulator.SpiderLink(dr);
			Assert.AreNotEqual(typeof(DBNull), dr["result"].GetType());
			Assert.AreEqual(dr["result"].ToString(), "");
		}
		[TestMethod(), TestCategory("Integration"), ExpectedException(typeof(ArgumentNullException))]
		public void SpiderLinkTest2()
		{
			Articleulator.Articleulator.SpiderLink(null);
		}
		[TestMethod(), TestCategory("Integration")]
		public void SpiderLinkTest3()
		{
			DataTable dt = KC.DataAccess.Global.Global.CallSql_Query(cs, "select top 1 * from links where result like '%banned%' order by id desc");
			if (dt == null || dt.Rows.Count == 0)
			{
				Assert.Inconclusive("No rows to test on.");
				return;
			}
			DataRow dr = dt.Rows[0];
			Articleulator.Articleulator.SpiderLink(dr);
			Assert.AreNotEqual(typeof(DBNull), dr["result"].GetType());
			Assert.AreEqual(dr["result"].ToString(), "Banned");
		}

		#endregion SpiderLink
		#region isValidWord

		[TestMethod(), TestCategory("Integration")]
		public void isValidWordTest1()
		{
			Assert.IsTrue(Articleulator.Articleulator.isValidWord("tomato", "tomato"));
		}
		[TestMethod(), TestCategory("Integration"), ExpectedException(typeof(ArgumentNullException))]
		public void isValidWordTest2()
		{
			Articleulator.Articleulator.isValidWord("true", null);
		}
		[TestMethod(), TestCategory("Integration"), ExpectedException(typeof(ArgumentNullException))]
		public void isValidWordTest3()
		{
			Assert.IsTrue(Articleulator.Articleulator.isValidWord(null, "true"));
		}
		[TestMethod(), TestCategory("Integration")]
		public void isValidWordTest4()
		{
			Assert.IsFalse(Articleulator.Articleulator.isValidWord("x", "x"));
			Assert.IsFalse(Articleulator.Articleulator.isValidWord("e", "e"));
			Assert.IsFalse(Articleulator.Articleulator.isValidWord("rq", "rq"));
			Assert.IsFalse(Articleulator.Articleulator.isValidWord("pdq", "pdq"));
			Assert.IsFalse(Articleulator.Articleulator.isValidWord("flrgn", "flrgn"));
			Assert.IsFalse(Articleulator.Articleulator.isValidWord("aeiaa", "aeiaa"));
		}

		#endregion isValidWord
		#region other

		[TestMethod(), TestCategory("Integration")]
		public void GetBodiesToParseTest()
		{
			List<DataRow> actual = Articleulator.Articleulator.GetBodiesToParse();
			Assert.IsTrue(actual.Count > 0);
			foreach (DataRow dr in actual)
				Assert.AreEqual(typeof(DBNull), dr["result"].GetType());
		}

		[TestMethod(), TestCategory("Integration")]
		public void GetLinksToSpiderTest()
		{
			List<DataRow> actual = Articleulator.Articleulator.GetLinksToSpider();
			Assert.IsTrue(actual.Count > 0);
			foreach (DataRow dr in actual)
				Assert.IsTrue(dr["result"].GetType() == typeof(DBNull) || dr["result"].ToString().Length == 0);
		}

		[TestMethod(), TestCategory("Integration")]
		public void GetSentencesToGenerateTest()
		{
			List<DataRow> actual = Articleulator.Articleulator.GetSentencesToGenerate();
			Assert.IsTrue(actual.Count > 0);
			foreach (DataRow dr in actual)
				Assert.IsTrue(dr["Source"].ToString() == "Extracted");
		}

		[TestMethod(), TestCategory("Integration")]
		public void GetSentencesToPublishTest()
		{
			List<string> actual = Articleulator.Articleulator.GetSentencesToPublish();
			Assert.IsTrue(actual.Count > 0);
			foreach (string str in actual) {
				Assert.IsFalse(string.IsNullOrEmpty(str));
				Assert.IsTrue(str.Length > 0); }
		}

		[TestMethod(), TestCategory("Integration")]
		public void ImportWordTest()
		{
			string word = "flarfarttitty";
			Articleulator.Articleulator.ImportWord(word);
			Assert.IsTrue(int.Parse(KC.DataAccess.Global.Global.CallSql_Query(cs, "select count(id) from words where word='" + word + "'").Rows[0][0].ToString()) > 0);
			KC.DataAccess.Global.Global.CallSql_Query(cs, "delete words where word='" + word + "'");
		}

		[TestMethod(), TestCategory("Integration")]
		public void WriteBlogPostTest()
		{
			string expected = string.Empty;
			string actual;
			string titleExpected = string.Empty;

			string title = string.Empty;
			actual = Articleulator.Articleulator.WriteBlogPost(out title);

			Assert.IsFalse(string.IsNullOrEmpty(actual));
 			Assert.IsFalse(string.IsNullOrEmpty(title));

			// count sentences
			int sent = 0;
			foreach (char c in actual)
				if (c == '.') sent++;
			Assert.AreEqual(50, sent);

			// Count paragraphs
			int para = 0;
			foreach (char c in actual)
				if (c == '\n') para++;
			Assert.AreEqual(10, para);
		}

		[TestMethod(), TestCategory("Integration")]
		[DeploymentItem("KC.Business.Articleulator.Articleulator.dll")]
		public void isUrlBannedTest()
		{
			string[] unbanned = new string[] { "http://kconnolly.net", "http://msdn.com", "https://iddqd" };
			string[] banned = new string[] { "http://doi.org", "http://fbi.gov", "http://www.army.mil", "http://newyorker.com" };
			foreach (string b in banned) { Assert.IsTrue(Articleulator.Articleulator.isUrlBanned(b), b); }
			foreach (string b in unbanned) { Assert.IsFalse(Articleulator.Articleulator.isUrlBanned(b), b); }
		}

		#endregion other

	}
}
